package com.sherler.crawler;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sherler.crawler.eastmoney.GubaPageProcessor;
import com.sherler.crawler.hexun.HexunBasicPageProcessor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.concurrent.Executor;

/**
 * Created by GeorgeSherler on 2017/4/3.
 */
public class CrawlerStarter extends AsyncConfigurerSupport implements CommandLineRunner {
    private String ThreadNamePrefix = "MyLogExecutor-";
    private int corePoolSize = 1;
    /** Set the ThreadPoolExecutor's maximum pool size. */
    private int maxPoolSize = 200;
    /** Set the capacity for the ThreadPoolExecutor's BlockingQueue. */
    private int queueCapacity = 1;

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("GithubLookup-");
        executor.initialize();
        return executor;
    }

    @Autowired
    private GubaPageProcessor gubaPageProcessor;

    @Autowired
    private HexunBasicPageProcessor hexunBasicPageProcessor;

    @Override
    public void run(String... args) throws Exception {
       gubaPageProcessor.start(395,"http://guba.eastmoney.com/default,1,f_1915.html","新闻");
    //    gubaPageProcessor.start(395,"http://guba.eastmoney.com/default,3,f_12000.html","公告");
    //    gubaPageProcessor.start(395,"http://guba.eastmoney.com/default,2,f_1.html","研报");
//        gubaPageProcessor.start(365,"http://guba.eastmoney.com/default,11,f_1.html","问董秘");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=184571007&s=30&priority=0","股票观察");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=165137500&s=30&priority=0","股票内参");
        // hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=100235849&s=30&priority=0","公司要闻");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=100235808&s=30&priority=0","证券要闻");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=100235812&s=30&priority=0","名家论市");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=100235806&s=30&priority=0","股市直播");
//        hexunBasicPageProcessor.start(395,"http://open.tool.hexun.com/MongodbNewsService/newsListPageByJson.jsp?id=100235839&s=30&priority=0","行业市况");
    }

    public static void main(String[] args){
        SpringApplication.run(CrawlerStarter.class,args);
    }

}
